<template>
	<view>
		<view class="avatar u-flex ">
			<!-- mine-top -->
			<u-avatar @click="gopages('/pages/home1/setuser/setuser')" size="132rpx" :src="user.wxpic"></u-avatar>
			<view style="margin-left: 20rpx;">
				{{ user.wxnc }}
			</view>
			<!-- #ifdef APP-PLUS -->
			<u-button class="exitLogin" @click="exitLogin" type="primary" plain shape="circle" text="退出登录"></u-button>
			<!-- #endif -->
		</view>
		<view class="moneybag">
			<view class="qbbox u-flex u-flex-end">
				<view class="u-flex ">
					<view class="cz" @click="gopages('/pages/recharge/recharge')">
						<text class="text">{{ $z.$t("充值") }}</text>
					</view>
					<view class="tk" @click="gopages('/pages/home1/bill/bill')">
						<text class="text">退款</text>
					</view>
				</view>
			</view>

			<view class="u-flex u-flex-between" style=" margin-top: 80rpx;">
				<view class="ye">
					<view class="text">{{ $z.$t("总余额") }}</view>
					<view class="je"> <text class="text">￥</text>{{ user.je / 100 || "0" }}</view>
				</view>
				<!-- <view v-if="area == 67">
					<view v-if="vip == 0" @click="gopages('/pages/home1/vip/vip')" class="vip-btn">
						<view class="btn-text">{{ $z.$t("成为会员") }}</view>
						<view class="sub-text">{{ $z.$t("去购买会员权益") }}</view>
					</view>
					<view v-else @click="gopages('/pages/home1/record/record')" class="vip-info">
						<view class="level">{{ level }}</view>
						<view class="discount">共计优惠：{{ validVip.jeyh ? validVip.jeyh / 100 : '0.00' }}元</view>
						<view class="validity">有效期{{ time }}</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="listcard">
			<view class="title">{{$z.$t("常用功能")}}</view>
			<view class="item" @click="gopages('/pages/userccp/userccp')">
				<view class="iconfont icon-cheliang-"></view>
				{{$z.$t("我的爱车")}}
			</view>

			<view class="item" @click="gopages('/pages/home1/SiteOften/SiteOften')">
				<view class="iconfont icon-shoucang"></view>
				{{$z.$t("我的收藏")}}
			</view>
			<view class="item" @click="gopages('/pages/FPcd/FPcd')">
				<view class="iconfont icon-zcpt-fapiaoguanli"></view>
				{{$z.$t("发票管理")}}
			</view>
			<view class="item" @click="jmtap()">
				<view class="iconfont icon-cooperation-full2"></view>
				{{$z.$t("我要加盟")}}
			</view>
			<view class="item" @click="gopages('/pages/StationCar/Stationgteltd/Stationgteltd?type=ChargeOften')">
				<view class="iconfont icon-chongdianzhuang"></view>
				{{$z.$t("常用充电桩")}}
			</view>
			<view class="item" @click="cardtap">
				<view class="iconfont icon-xinyongqia"></view>
				{{$z.$t("卡管理")}}
			</view>
			<!-- <view style="width: 180rpx"></view>
      <view style="width: 180rpx"></view> -->
		</view>
		<ztabbar></ztabbar>
		<zmodal ref="zmodal"></zmodal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				vip: 0,
				validVip: {},
				// user: {},
				area: ''
			};
		},
		mounted() {
			this.init();

		},
		computed: {
			user() {
				let r = this.$store.state.user.USearch
				return r
			},
			level() {
				if (this.validVip.mc == 0) {
					return '黄金会员'
				} else if (this.validVip.mc == 1) {
					return '白金会员'
				} else if (this.validVip.mc == 2) {
					return '钻石会员'
				}
			},
			time() {
				return `${this.validVip.sjs.split(' ')[0]}至${this.validVip.sje.split(' ')[0]}`
			}
		},
		methods: {
			async getVip(val) {
				let CarRanklog = await this.$z.request("/CarRanklog", {
					uUser: val.uUser,
				});
				// CarRanklog = [{
				// 	area: 0,
				// 	b_use: 1,
				// 	ddh: 88888888888888,
				// 	id: 6,
				// 	je: 1,
				// 	mc: 0,
				// 	sjc: '2025-08-22 14:53:07',
				// 	sje: '2025-08-22 00:00:00',
				// 	sjs: '2025-07-22 00:00:00',
				// 	uUser: 'adkjadlk',
				// 	zk: 9,
				// }, {
				// 	area: 0,
				// 	b_use: 1,
				// 	ddh: 88888888888888,
				// 	id: 6,
				// 	je: 1,
				// 	mc: 0,
				// 	sjc: '2025-08-22 14:53:07',
				// 	sje: '2025-09-22 00:00:00',
				// 	sjs: '2025-08-22 00:00:00',
				// 	uUser: 'adkjadlk',
				// 	zk: 9,
				// }]
				// 检查是否有会员记录
				if (!CarRanklog || CarRanklog.length === 0) {
					this.vip = 0; // 没有会员
					return;
				}

				// 获取当前时间
				const now = new Date();

				// 查找在有效期内的会员记录
				const validVip = CarRanklog.find(item => {
					const startTime = new Date(item.sjs);
					const endTime = new Date(item.sje);
					return now >= startTime && now <= endTime;
				});
				this.validVip = validVip;
				console.log('validVip', validVip)
				// 设置会员状态
				this.vip = validVip ? 1 : 0; // 1表示是会员，0表示不是会员
			},
			async init() {
				let user = await this.$store.dispatch("user/getuser");
				this.area = user.area;
				await this.getVip(user)
				console.log(user, "user");
			},
			gopages(url) {
				uni.navigateTo({
					url: url
				})
			},
			jmtap() {
				this.$refs.zmodal.init({
					showcancel: true,
					confirmText: "拨打",
					content: `${this.$z.$t("拨打客服电话")}${this.$store.state.config.kfutel},${this.$z.$t("工作时间为")}8:30--22:00，${this.$z.$t("其他时间会转留言")}.`,
					confirm: () => {
						uni.makePhoneCall({
							phoneNumber: this.$store.state.config.kfuteltest //仅为示例
						});
					}
				})
			},
			cardtap() {
				if (!this.user.printid) {
					this.$refs.zmodal.init({
						content: this.$z.$t("您还没有绑定卡，立即绑定？"),
						showcancel: true,
						confirm: () => {
							uni.navigateTo({
								url: "/pages/card/CardTouUseradd/CardTouUseradd"
							})
						}
					})
					return
				}
				uni.navigateTo({
					url: "/pages/card/Cardsetting/Cardsetting"
				})
				console.log(123456, this.user.printid);
			},
			exitLogin() {
				uni.reLaunch({
					url: '/pages/login/login'
				});
			}
		},
	};
</script>

<style lang="scss">
	page {
		background: linear-gradient(#e2eef4, #f4f7f8);
		min-height: 100vh;
	}

	.mine-top {
		justify-content: space-between;
	}

	.listcard {
		margin: 30rpx;
		background: #ffffff;
		border-radius: 20rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		padding-bottom: 38rpx;
		padding-top: 26rpx;

		.title {
			font-size: 36rpx;
			padding-left: 30rpx;
			font-weight: bold;
			width: 750rpx;
			line-height: 60rpx;
		}

		.item {
			display: flex;
			flex-direction: column;
			font-size: 32rpx;
			justify-content: center;
			align-items: center;
			width: 180rpx;
			font-size: 28rpx;
			margin-top: 10rpx;

			// padding: 0 20rpx;
			.iconfont {
				width: 100rpx;
				height: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 60rpx;
				color: #319fff;
			}
		}
	}

	.avatar {
		position: relative;
		padding: 40rpx 30rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.moneybag {
		background-image: url('@/static/infp-bg.png');
		background-size: cover;
		background-repeat: no-repeat;
		background-position: center;
		height: 320rpx;
		margin: 0 30rpx;
		border-radius: 20rpx;
		padding: 30rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);

		.qbbox {
			font-size: 32rpx;
			padding: 0;

			.title-text {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
				margin-left: 10rpx;
			}

			.cz {
				width: 120rpx;
				height: 60rpx;
				background-color: #FFF4D9;
				border-radius: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 20rpx;
				border: 2rpx solid #f5c37a;

				.text {
					font-size: 28rpx;
					color: #C07616;
					// font-weight: bold;
				}
			}

			.tk {
				width: 120rpx;
				height: 60rpx;
				background-color: #585459;
				border-radius: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border: 2rpx solid #8d6529;

				.text {
					font-size: 28rpx;
					color: #FFEDD6;
					// font-weight: bold;
				}
			}
		}

		.ye {
			padding-left: 0;
			flex-direction: column;
			align-items: flex-start;

			.text {
				font-size: 28rpx;
				color: #C07616;
				margin-bottom: 20rpx;
			}

			.je {
				font-size: 56rpx;
				font-weight: bold;
				color: #C07616;

				.text {
					font-size: 48rpx;
					color: #C07616;
				}
			}
		}

		.vip-btn {
			text-align: center;
			color: #8d6529;
			font-size: 28rpx;
			line-height: 1.5;

			.btn-text {
				// font-weight: bold;
				font-size: 32rpx;
				color: #C07616;
			}

			.sub-text {
				font-size: 24rpx;
				color: #C07616;
				margin-top: 10rpx;
				text-decoration: underline;
			}
		}

		.vip-info {
			text-align: right;
			// color: #8d6529;
			// font-size: 28rpx;
			// line-height: 1.5;

			.level {
				font-weight: bold;
				font-size: 24rpx;
				color: #C07616;
				margin-bottom: 15rpx;
			}

			.discount {
				font-size: 20rpx;
				color: #C07616;
				margin-bottom: 15rpx;
			}

			.validity {
				font-size: 20rpx;
				color: #C07616;
			}
		}
	}


	.exitLogin {
		width: 200rpx;
		margin: 0;
	}
</style>